package 优先算法.滑动窗口.无重复字符的最长子串;

/**
 *https://leetcode.cn/problems/minimum-size-subarray-sum/
 */

import java.util.HashSet;
import java.util.Set;

public class MaxCharSet {
    public static void main(String[] args) {
        Solution so = new Solution();
        String s = "deabcabca";
        int rel = so.lengthOfLongestSubstring(s);
        System.out.println(rel);
    }
}
class Solution {
    public int lengthOfLongestSubstring(String s) {
        int len=0;

        Set<Character> set=new HashSet<Character>();
        for(int left=0,right=0;left<s.length();left++){
            //进窗口
            while(right < s.length() && !set.contains(s.charAt(right))){
                set.add(s.charAt(right++));
            }
            //出窗口
            len=Math.max(len,right-left);
            //更新
            set.remove(s.charAt(left));
        }
        return len;
    }
}